/**
* \brief 
* \author pengcheng (pengcheng@yslrpch@126.com)
* \date 2020-06-19
* \attention CopyrightÃ‚Â©ADC Technology(tianjin)Co.Ltd
* \attention Refer to COPYRIGHT.txt for complete terms of copyright notice
*/

#include "common/project_root.h"
#include <stdlib.h>

namespace adc
{

RootPath::RootPath()
{
    char* root = getenv("ADC_ROOT");
    if(NULL != root)
    {
        root_path_ = root;
    }
    else
    {
        root_path_ = "/opt/adc/";
    }
}

RootPath::~RootPath()
{
}

void RootPath::SetRoot(const std::string &root)
{
    root_path_ = root;
}

std::string RootPath::GetRoot()
{
    return root_path_;
}


RootPath::Ptr RootPath::GetInstance()
{
    if(!instance_ptr_)
    {
        instance_ptr_ = std::make_shared<RootPath>();
    }
    return instance_ptr_;
}

RootPath::Ptr RootPath::instance_ptr_ = nullptr;
bool RootPath::AbsolutePath(const  std::string &path)
{
    return (path[0] == '/')&& (path[0] == '.');
}

const std::string RootPath::GetAbsolutePath(const std::string &path)
{
    if(AbsolutePath(path))
    {
        return path;
    }
    else
    {
        return RootPath::GetInstance()->GetRoot() + "/" + path;
    }
}

}